### Load required packages

library(sandwich)
library(lmtest)
library(multiwayvcov)
library(stargazer)
library(ggplot2)
library(ggpubr)
library(plyr)
library(gridExtra)

RBacklashData <- read.csv("RBacklashData.csv") #1988-2019, 24 countries
RBacklashData <- RBacklashData[RBacklashData$year >= 1989 & RBacklashData$year <= 2017,]
RBacklashData$FRPvoteshare_int <- RBacklashData$FRPvoteshare_int/100
RBacklashData$populismscoreTRW <- RBacklashData$populismscoreTRW/100

### Load the dataset

data <- read.csv("Dennison_POQ2023.csv")

## Variable descriptions

# electionyear: the year of elections
# populismscoreTRW: vote share of RWP parties in Timbro (duplicated for post-election years)
# FRPvoteshare_int/FRPseatshare_int/FRPpresence_int: 0-1 vote share/seat share/presence of FRP in PopuList (duplicated for post-election years)
# voterscore_01: anti-immigration score from Caughey et al.
# voterscore2_01: anti-immigration score from Claasen
# voterscore3_01: combined anti-immigration score from Coughey and Claassen
# voterscoreecon_01: economic ideology score from Caughey et al.
# voterscore3BE: combined anti-immigration score aggregated across elections
# imm_stock_lag/lnunemployment_lag/lngdppc_lag: control variables from WB/OECD lagged by one year

### Descriptive Analysis

cor(data$populismscoreTRW, data$FRPseatshare_int, use = "complete.obs") #0.91
cor(data[c("voterscore_01", "voterscore2_01", "voterscore3_01")], use = "complete.obs") #0.8

### Table 1 Anti-immigration attitudes as a function of RPP entring government

H1M1a <- lm(voterscore3_01 ~ FRPpresence_int + factor(country), data)
H1M1b <- lm(voterscore3_01 ~ FRPseatshare_int + factor(country), data)
H1M1c <- lm(voterscore3_01 ~ FRPvoteshare_int + factor(country), data)
H1M1d <- lm(voterscore3_01 ~ populismscoreTRW + factor(country), data)
rob.se.H1M1a <- sqrt(diag(vcovHC(H1M1a, type = "HC3")))
rob.se.H1M1b <- sqrt(diag(vcovHC(H1M1b, type = "HC3")))
rob.se.H1M1c <- sqrt(diag(vcovHC(H1M1c, type = "HC3")))
rob.se.H1M1d <- sqrt(diag(vcovHC(H1M1d, type = "HC3")))
cl.se.H1M1a <- sqrt(diag(cluster.vcov(H1M1a, data$country)))
cl.se.H1M1b <- sqrt(diag(cluster.vcov(H1M1b, data$country)))
cl.se.H1M1c <- sqrt(diag(cluster.vcov(H1M1c, data$country)))
cl.se.H1M1d <- sqrt(diag(cluster.vcov(H1M1d, data$country)))

H1M2a <- lm(voterscore3_01 ~ FRPpresence_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag, data)
H1M2b <- lm(voterscore3_01 ~ FRPseatshare_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag, data)
H1M2c <- lm(voterscore3_01 ~ FRPvoteshare_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag, data)
H1M2d <- lm(voterscore3_01 ~ populismscoreTRW + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag, data)
rob.se.H1M2a <- sqrt(diag(vcovHC(H1M2a, type = "HC3")))
rob.se.H1M2b <- sqrt(diag(vcovHC(H1M2b, type = "HC3")))
rob.se.H1M2c <- sqrt(diag(vcovHC(H1M2c, type = "HC3")))
rob.se.H1M2d <- sqrt(diag(vcovHC(H1M2d, type = "HC3")))
cl.se.H1M2a <- sqrt(diag(cluster.vcov(H1M2a, data$country)))
cl.se.H1M2b <- sqrt(diag(cluster.vcov(H1M2b, data$country)))
cl.se.H1M2c <- sqrt(diag(cluster.vcov(H1M2c, data$country)))
cl.se.H1M2d <- sqrt(diag(cluster.vcov(H1M2d, data$country)))

H1M3a <- lm(voterscore3_01 ~ FRPpresence_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag + factor(year), data)
H1M3b <- lm(voterscore3_01 ~ FRPseatshare_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag + factor(year), data)
H1M3c <- lm(voterscore3_01 ~ FRPvoteshare_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag + factor(year), data)
H1M3d <- lm(voterscore3_01 ~ populismscoreTRW + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag + factor(year), data)
rob.se.H1M3a <- sqrt(diag(vcovHC(H1M3a, type = "HC3")))
rob.se.H1M3b <- sqrt(diag(vcovHC(H1M3b, type = "HC3")))
rob.se.H1M3c <- sqrt(diag(vcovHC(H1M3c, type = "HC3")))
rob.se.H1M3d <- sqrt(diag(vcovHC(H1M3d, type = "HC3")))
cl.se.H1M3a <- sqrt(diag(cluster.vcov(H1M3a, data$country)))
cl.se.H1M3b <- sqrt(diag(cluster.vcov(H1M3b, data$country)))
cl.se.H1M3c <- sqrt(diag(cluster.vcov(H1M3c, data$country)))
cl.se.H1M3d <- sqrt(diag(cluster.vcov(H1M3d, data$country)))

library(stargazer)

stargazer(H1M1b, H1M2b, H1M3b, H1M1c, H1M2c, H1M3c, H1M1d, H1M2d, H1M3d, dep.var.caption = "",
          se=list(rob.se.H1M1b, rob.se.H1M2b, rob.se.H1M3b,
                  rob.se.H1M1c, rob.se.H1M2c, rob.se.H1M3c,
                  rob.se.H1M1d, rob.se.H1M2d, rob.se.H1M3d), 
          title="Populist Right Electoral Success and Anti-Immigration Attitudes", 
          dep.var.labels=c("Anti-immigration attitudes"),
          covariate.labels=c("Far-right populist (seat share)", "Far-right populist (vote share)", "Right-wing populist (vote share)"),
          align=TRUE, no.space=TRUE, column.sep.width = "-20pt", 
          omit = c("country", "year", "Constant", "imm_stock_lag", "lnunemployment_lag", "lngdppc_lag"),
          omit.stat=c("rsq", "ser", "f"), notes = "", notes.append = F,  notes.label = "",
          star.char = c("*", "**", "***"), star.cutoffs = c(0.05, 0.01, 0.001), out="ModelsCombined.htm",
          add.lines = list(c("Country FE", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes"),
                           c("Controls", "No", "Yes", "Yes", "No", "Yes", "Yes", "No", "Yes", "Yes"),
                           c("Year FE", "No", "No", "Yes", "No", "No", "Yes", "No", "No", "Yes")))

# Table S1

stargazer(H1M1b, H1M2b, H1M3b, H1M1c, H1M2c, H1M3c, H1M1d, H1M2d, H1M3d, dep.var.caption = "",
          se=list(cl.se.H1M1b, cl.se.H1M2b, cl.se.H1M3b,
                  cl.se.H1M1c, cl.se.H1M2c, cl.se.H1M3c,
                  cl.se.H1M1d, cl.se.H1M2d, cl.se.H1M3d), 
          title="Populist Right Electoral Success and Anti-Immigration Attitudes", 
          dep.var.labels=c("Anti-immigration attitudes"),
          covariate.labels=c("Far-right populist (seat share)", "Far-right populist (vote share)", "Right-wing populist (vote share)"),
          align=TRUE, no.space=TRUE, column.sep.width = "-20pt", 
          omit = c("country", "year", "Constant", "imm_stock_lag", "lnunemployment_lag", "lngdppc_lag"),
          omit.stat=c("rsq", "ser", "f"), notes = "", notes.append = F,  notes.label = "",
          star.char = c("*", "**", "***"), star.cutoffs = c(0.05, 0.01, 0.001), out="ModelsCombinedClustered.htm",
          add.lines = list(c("Country FE", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes"),
                           c("Controls", "No", "Yes", "Yes", "No", "Yes", "Yes", "No", "Yes", "Yes"),
                           c("Year FE", "No", "No", "Yes", "No", "No", "Yes", "No", "No", "Yes")))

### Table S2 Anti-immigration attitudes as a function of RPP entring government (Caughey DV)

H1M1a <- lm(voterscore_01 ~ FRPpresence_int + factor(country), data)
H1M1b <- lm(voterscore_01 ~ FRPseatshare_int + factor(country), data)
H1M1c <- lm(voterscore_01 ~ FRPvoteshare_int + factor(country), data)
H1M1d <- lm(voterscore_01 ~ populismscoreTRW + factor(country), data)
rob.se.H1M1a <- sqrt(diag(vcovHC(H1M1a, type = "HC3")))
rob.se.H1M1b <- sqrt(diag(vcovHC(H1M1b, type = "HC3")))
rob.se.H1M1c <- sqrt(diag(vcovHC(H1M1c, type = "HC3")))
rob.se.H1M1d <- sqrt(diag(vcovHC(H1M1d, type = "HC3")))
cl.se.H1M1a <- sqrt(diag(cluster.vcov(H1M1a, data$country)))
cl.se.H1M1b <- sqrt(diag(cluster.vcov(H1M1b, data$country)))
cl.se.H1M1c <- sqrt(diag(cluster.vcov(H1M1c, data$country)))
cl.se.H1M1d <- sqrt(diag(cluster.vcov(H1M1d, data$country)))

H1M2a <- lm(voterscore_01 ~ FRPpresence_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag, data)
H1M2b <- lm(voterscore_01 ~ FRPseatshare_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag, data)
H1M2c <- lm(voterscore_01 ~ FRPvoteshare_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag, data)
H1M2d <- lm(voterscore_01 ~ populismscoreTRW + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag, data)
rob.se.H1M2a <- sqrt(diag(vcovHC(H1M2a, type = "HC3")))
rob.se.H1M2b <- sqrt(diag(vcovHC(H1M2b, type = "HC3")))
rob.se.H1M2c <- sqrt(diag(vcovHC(H1M2c, type = "HC3")))
rob.se.H1M2d <- sqrt(diag(vcovHC(H1M2d, type = "HC3")))
cl.se.H1M2a <- sqrt(diag(cluster.vcov(H1M2a, data$country)))
cl.se.H1M2b <- sqrt(diag(cluster.vcov(H1M2b, data$country)))
cl.se.H1M2c <- sqrt(diag(cluster.vcov(H1M2c, data$country)))
cl.se.H1M2d <- sqrt(diag(cluster.vcov(H1M2d, data$country)))

H1M3a <- lm(voterscore_01 ~ FRPpresence_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag + factor(year), data)
H1M3b <- lm(voterscore_01 ~ FRPseatshare_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag + factor(year), data)
H1M3c <- lm(voterscore_01 ~ FRPvoteshare_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag + factor(year), data)
H1M3d <- lm(voterscore_01 ~ populismscoreTRW + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag + factor(year), data)
rob.se.H1M3a <- sqrt(diag(vcovHC(H1M3a, type = "HC3")))
rob.se.H1M3b <- sqrt(diag(vcovHC(H1M3b, type = "HC3")))
rob.se.H1M3c <- sqrt(diag(vcovHC(H1M3c, type = "HC3")))
rob.se.H1M3d <- sqrt(diag(vcovHC(H1M3d, type = "HC3")))
cl.se.H1M3a <- sqrt(diag(cluster.vcov(H1M3a, data$country)))
cl.se.H1M3b <- sqrt(diag(cluster.vcov(H1M3b, data$country)))
cl.se.H1M3c <- sqrt(diag(cluster.vcov(H1M3c, data$country)))
cl.se.H1M3d <- sqrt(diag(cluster.vcov(H1M3d, data$country)))

library(stargazer)

stargazer(H1M1b, H1M2b, H1M3b, H1M1c, H1M2c, H1M3c, H1M1d, H1M2d, H1M3d, dep.var.caption = "",
          se=list(rob.se.H1M1b, rob.se.H1M2b, rob.se.H1M3b,
                  rob.se.H1M1c, rob.se.H1M2c, rob.se.H1M3c,
                  rob.se.H1M1d, rob.se.H1M2d, rob.se.H1M3d), 
          title="Populist Right Electoral Success and Anti-Immigration Attitudes", 
          dep.var.labels=c("Anti-immigration attitudes (Caughey et al.)"),
          covariate.labels=c("Far-right populist (seat share)", "Far-right populist (vote share)", "Right-wing populist (vote share)"),
          align=TRUE, no.space=TRUE, column.sep.width = "-20pt", 
          omit = c("country", "year", "Constant", "imm_stock_lag", "lnunemployment_lag", "lngdppc_lag"),
          omit.stat=c("rsq", "ser", "f"), notes = "", notes.append = F,  notes.label = "",
          star.char = c("*", "**", "***"), star.cutoffs = c(0.05, 0.01, 0.001), out="ModelsCaughey.htm",
          add.lines = list(c("Country FE", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes"),
                           c("Controls", "No", "Yes", "Yes", "No", "Yes", "Yes", "No", "Yes", "Yes"),
                           c("Year FE", "No", "No", "Yes", "No", "No", "Yes", "No", "No", "Yes")))

### Table S3 Anti-immigration attitudes as a function of RPP entring government (Claasen DV)

H1M1a <- lm(voterscore2_01 ~ FRPpresence_int + factor(country), data)
H1M1b <- lm(voterscore2_01 ~ FRPseatshare_int + factor(country), data)
H1M1c <- lm(voterscore2_01 ~ FRPvoteshare_int + factor(country), data)
H1M1d <- lm(voterscore2_01 ~ populismscoreTRW + factor(country), data)
rob.se.H1M1a <- sqrt(diag(vcovHC(H1M1a, type = "HC3")))
rob.se.H1M1b <- sqrt(diag(vcovHC(H1M1b, type = "HC3")))
rob.se.H1M1c <- sqrt(diag(vcovHC(H1M1c, type = "HC3")))
rob.se.H1M1d <- sqrt(diag(vcovHC(H1M1d, type = "HC3")))
cl.se.H1M1a <- sqrt(diag(cluster.vcov(H1M1a, data$country)))
cl.se.H1M1b <- sqrt(diag(cluster.vcov(H1M1b, data$country)))
cl.se.H1M1c <- sqrt(diag(cluster.vcov(H1M1c, data$country)))
cl.se.H1M1d <- sqrt(diag(cluster.vcov(H1M1d, data$country)))

H1M2a <- lm(voterscore2_01 ~ FRPpresence_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag, data)
H1M2b <- lm(voterscore2_01 ~ FRPseatshare_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag, data)
H1M2c <- lm(voterscore2_01 ~ FRPvoteshare_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag, data)
H1M2d <- lm(voterscore2_01 ~ populismscoreTRW + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag, data)
rob.se.H1M2a <- sqrt(diag(vcovHC(H1M2a, type = "HC3")))
rob.se.H1M2b <- sqrt(diag(vcovHC(H1M2b, type = "HC3")))
rob.se.H1M2c <- sqrt(diag(vcovHC(H1M2c, type = "HC3")))
rob.se.H1M2d <- sqrt(diag(vcovHC(H1M2d, type = "HC3")))
cl.se.H1M2a <- sqrt(diag(cluster.vcov(H1M2a, data$country)))
cl.se.H1M2b <- sqrt(diag(cluster.vcov(H1M2b, data$country)))
cl.se.H1M2c <- sqrt(diag(cluster.vcov(H1M2c, data$country)))
cl.se.H1M2d <- sqrt(diag(cluster.vcov(H1M2d, data$country)))

H1M3a <- lm(voterscore2_01 ~ FRPpresence_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag + factor(year), data)
H1M3b <- lm(voterscore2_01 ~ FRPseatshare_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag + factor(year), data)
H1M3c <- lm(voterscore2_01 ~ FRPvoteshare_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag + factor(year), data)
H1M3d <- lm(voterscore2_01 ~ populismscoreTRW + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag + factor(year), data)
rob.se.H1M3a <- sqrt(diag(vcovHC(H1M3a, type = "HC3")))
rob.se.H1M3b <- sqrt(diag(vcovHC(H1M3b, type = "HC3")))
rob.se.H1M3c <- sqrt(diag(vcovHC(H1M3c, type = "HC3")))
rob.se.H1M3d <- sqrt(diag(vcovHC(H1M3d, type = "HC3")))
cl.se.H1M3a <- sqrt(diag(cluster.vcov(H1M3a, data$country)))
cl.se.H1M3b <- sqrt(diag(cluster.vcov(H1M3b, data$country)))
cl.se.H1M3c <- sqrt(diag(cluster.vcov(H1M3c, data$country)))
cl.se.H1M3d <- sqrt(diag(cluster.vcov(H1M3d, data$country)))

stargazer(H1M1b, H1M2b, H1M3b, H1M1c, H1M2c, H1M3c, H1M1d, H1M2d, H1M3d, dep.var.caption = "",
          se=list(rob.se.H1M1b, rob.se.H1M2b, rob.se.H1M3b,
                  rob.se.H1M1c, rob.se.H1M2c, rob.se.H1M3c,
                  rob.se.H1M1d, rob.se.H1M2d, rob.se.H1M3d), 
          title="Populist Right Electoral Success and Anti-Immigration Attitudes", 
          dep.var.labels=c("Anti-immigration attitudes (Claassen and McLaren)"),
          covariate.labels=c("Far-right populist (seat share)", "Far-right populist (vote share)", "Right-wing populist (vote share)"),
          align=TRUE, no.space=TRUE, column.sep.width = "-20pt", 
          omit = c("country", "year", "Constant", "imm_stock_lag", "lnunemployment_lag", "lngdppc_lag"),
          omit.stat=c("rsq", "ser", "f"), notes = "", notes.append = F,  notes.label = "",
          star.char = c("*", "**", "***"), star.cutoffs = c(0.05, 0.01, 0.001), out="ModelsClaassen.htm",
          add.lines = list(c("Country FE", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes"),
                           c("Controls", "No", "Yes", "Yes", "No", "Yes", "Yes", "No", "Yes", "Yes"),
                           c("Year FE", "No", "No", "Yes", "No", "No", "Yes", "No", "No", "Yes")))

### Table S4 Economic Conservatism as a function of RPPP success (Placebo, Caughey DV)

H1M1a <- lm(voterscoreecon_01 ~ FRPpresence_int + factor(country), data)
H1M1b <- lm(voterscoreecon_01 ~ FRPseatshare_int + factor(country), data)
H1M1c <- lm(voterscoreecon_01 ~ FRPvoteshare_int + factor(country), data)
H1M1d <- lm(voterscoreecon_01 ~ populismscoreTRW + factor(country), data)
rob.se.H1M1a <- sqrt(diag(vcovHC(H1M1a, type = "HC3")))
rob.se.H1M1b <- sqrt(diag(vcovHC(H1M1b, type = "HC3")))
rob.se.H1M1c <- sqrt(diag(vcovHC(H1M1c, type = "HC3")))
rob.se.H1M1d <- sqrt(diag(vcovHC(H1M1d, type = "HC3")))
cl.se.H1M1a <- sqrt(diag(cluster.vcov(H1M1a, data$country)))
cl.se.H1M1b <- sqrt(diag(cluster.vcov(H1M1b, data$country)))
cl.se.H1M1c <- sqrt(diag(cluster.vcov(H1M1c, data$country)))
cl.se.H1M1d <- sqrt(diag(cluster.vcov(H1M1d, data$country)))

H1M2a <- lm(voterscoreecon_01 ~ FRPpresence_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag, data)
H1M2b <- lm(voterscoreecon_01 ~ FRPseatshare_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag, data)
H1M2c <- lm(voterscoreecon_01 ~ FRPvoteshare_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag, data)
H1M2d <- lm(voterscoreecon_01 ~ populismscoreTRW + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag, data)
rob.se.H1M2a <- sqrt(diag(vcovHC(H1M2a, type = "HC3")))
rob.se.H1M2b <- sqrt(diag(vcovHC(H1M2b, type = "HC3")))
rob.se.H1M2c <- sqrt(diag(vcovHC(H1M2c, type = "HC3")))
rob.se.H1M2d <- sqrt(diag(vcovHC(H1M2d, type = "HC3")))
cl.se.H1M2a <- sqrt(diag(cluster.vcov(H1M2a, data$country)))
cl.se.H1M2b <- sqrt(diag(cluster.vcov(H1M2b, data$country)))
cl.se.H1M2c <- sqrt(diag(cluster.vcov(H1M2c, data$country)))
cl.se.H1M2d <- sqrt(diag(cluster.vcov(H1M2d, data$country)))

H1M3a <- lm(voterscoreecon_01 ~ FRPpresence_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag + factor(year), data)
H1M3b <- lm(voterscoreecon_01 ~ FRPseatshare_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag + factor(year), data)
H1M3c <- lm(voterscoreecon_01 ~ FRPvoteshare_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag + factor(year), data)
H1M3d <- lm(voterscoreecon_01 ~ populismscoreTRW + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag + factor(year), data)
rob.se.H1M3a <- sqrt(diag(vcovHC(H1M3a, type = "HC3")))
rob.se.H1M3b <- sqrt(diag(vcovHC(H1M3b, type = "HC3")))
rob.se.H1M3c <- sqrt(diag(vcovHC(H1M3c, type = "HC3")))
rob.se.H1M3d <- sqrt(diag(vcovHC(H1M3d, type = "HC3")))
cl.se.H1M3a <- sqrt(diag(cluster.vcov(H1M3a, data$country)))
cl.se.H1M3b <- sqrt(diag(cluster.vcov(H1M3b, data$country)))
cl.se.H1M3c <- sqrt(diag(cluster.vcov(H1M3c, data$country)))
cl.se.H1M3d <- sqrt(diag(cluster.vcov(H1M3d, data$country)))

stargazer(H1M1b, H1M2b, H1M3b, H1M1c, H1M2c, H1M3c, H1M1d, H1M2d, H1M3d, dep.var.caption = "",
          se=list(rob.se.H1M1b, rob.se.H1M2b, rob.se.H1M3b,
                  rob.se.H1M1c, rob.se.H1M2c, rob.se.H1M3c,
                  rob.se.H1M1d, rob.se.H1M2d, rob.se.H1M3d), 
          title="Populist Right Electoral Success and Economic Conservatism (Placebo Test)", 
          dep.var.labels=c("Economic Conservatism (Caughey et al.)"),
          covariate.labels=c("Far-right populist (seat share)", "Far-right populist (vote share)", "Right-wing populist (vote share)"),
          align=TRUE, no.space=TRUE, column.sep.width = "-20pt", 
          omit = c("country", "year", "Constant", "imm_stock_lag", "lnunemployment_lag", "lngdppc_lag"),
          omit.stat=c("rsq", "ser", "f"), notes = "", notes.append = F,  notes.label = "",
          star.char = c("*", "**", "***"), star.cutoffs = c(0.05, 0.01, 0.001), out="ModelsCaugheyEcon.htm",
          add.lines = list(c("Country FE", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes"),
                           c("Controls", "No", "Yes", "Yes", "No", "Yes", "Yes", "No", "Yes", "Yes"),
                           c("Year FE", "No", "No", "Yes", "No", "No", "Yes", "No", "No", "Yes")))

### Table A5 Anti-immigration attitudes as a function of RPPP success (election level)

H1M1a <- lm(voterscore3BE ~ FRPpresence_int + factor(country), data[data$electionyear == 1,])
H1M1b <- lm(voterscore3BE ~ FRPseatshare_int + factor(country), data[data$electionyear == 1,])
H1M1c <- lm(voterscore3BE ~ FRPvoteshare_int + factor(country), data[data$electionyear == 1,])
H1M1d <- lm(voterscore3BE ~ populismscoreTRW + factor(country), data[data$electionyear == 1,])
rob.se.H1M1a <- sqrt(diag(vcovHC(H1M1a, type = "HC3")))
rob.se.H1M1b <- sqrt(diag(vcovHC(H1M1b, type = "HC3")))
rob.se.H1M1c <- sqrt(diag(vcovHC(H1M1c, type = "HC3")))
rob.se.H1M1d <- sqrt(diag(vcovHC(H1M1d, type = "HC3")))

H1M2a <- lm(voterscore3BE ~ FRPpresence_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag, data[data$electionyear == 1,])
H1M2b <- lm(voterscore3BE ~ FRPseatshare_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag, data[data$electionyear == 1,])
H1M2c <- lm(voterscore3BE ~ FRPvoteshare_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag, data[data$electionyear == 1,])
H1M2d <- lm(voterscore3BE ~ populismscoreTRW + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag, data[data$electionyear == 1,])
rob.se.H1M2a <- sqrt(diag(vcovHC(H1M2a, type = "HC3")))
rob.se.H1M2b <- sqrt(diag(vcovHC(H1M2b, type = "HC3")))
rob.se.H1M2c <- sqrt(diag(vcovHC(H1M2c, type = "HC3")))
rob.se.H1M2d <- sqrt(diag(vcovHC(H1M2d, type = "HC3")))

H1M3a <- lm(voterscore3BE ~ FRPpresence_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag + factor(year), data[data$electionyear == 1,])
H1M3b <- lm(voterscore3BE ~ FRPseatshare_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag + factor(year), data[data$electionyear == 1,])
H1M3c <- lm(voterscore3BE ~ FRPvoteshare_int + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag + factor(year), data[data$electionyear == 1,])
H1M3d <- lm(voterscore3BE ~ populismscoreTRW + factor(country) + imm_stock_lag + lnunemployment_lag + lngdppc_lag + factor(year), data[data$electionyear == 1,])
rob.se.H1M3a <- sqrt(diag(vcovHC(H1M3a, type = "HC3")))
rob.se.H1M3b <- sqrt(diag(vcovHC(H1M3b, type = "HC3")))
rob.se.H1M3c <- sqrt(diag(vcovHC(H1M3c, type = "HC3")))
rob.se.H1M3d <- sqrt(diag(vcovHC(H1M3d, type = "HC3")))

library(stargazer)

stargazer(H1M1b, H1M2b, H1M3b, H1M1c, H1M2c, H1M3c, H1M1d, H1M2d, H1M3d, dep.var.caption = "",
          se=list(rob.se.H1M1b, rob.se.H1M2b, rob.se.H1M3b,
                  rob.se.H1M1c, rob.se.H1M2c, rob.se.H1M3c,
                  rob.se.H1M1d, rob.se.H1M2d, rob.se.H1M3d), 
          title="Populist Right Electoral Success and Anti-Immigration Attitudes (Election-Level)", 
          dep.var.labels=c("Anti-immigration attitudes"),
          covariate.labels=c("Far-right populist (seat share)", "Far-right populist (vote share)", "Right-wing populist (vote share)"),
          align=TRUE, no.space=TRUE, column.sep.width = "-20pt", 
          omit = c("country", "year", "Constant", "imm_stock_lag", "lnunemployment_lag", "lngdppc_lag"),
          omit.stat=c("rsq", "ser", "f"), notes = "", notes.append = F,  notes.label = "",
          star.char = c("+", "*", "**", "***"), star.cutoffs = c(0.1, 0.05, 0.01, 0.001), out="ModelsCombinedElection.htm",
          add.lines = list(c("Country FE", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes"),
                           c("Controls", "No", "Yes", "Yes", "No", "Yes", "Yes", "No", "Yes", "Yes"),
                           c("Year FE", "No", "No", "Yes", "No", "No", "Yes", "No", "No", "Yes")))

##### FIGURES

## Plot pulled data across time

ggplot(data, aes(x=year, y=FRPseatshare_int)) + #stat_summary(fun="mean", geom="point") +
  stat_summary(fun="mean", geom="line", color = "black", alpha=1, linetype = 2) +
  stat_summary(aes(x=as.numeric(year), y=as.numeric(FRPvoteshare_int)), fun="mean", geom="line", color="black", alpha=0.5, linetype = 2) +
  stat_summary(aes(x=as.numeric(year), y=as.numeric(populismscoreTRW)), fun="mean", geom="line", color="black", alpha=0.2, linetype = 2) +
  stat_summary(aes(x=as.numeric(year), y=as.numeric(voterscore3_01)), fun="mean", geom="line", color="black", alpha=1) +
  stat_summary(aes(x=as.numeric(year), y=as.numeric(voterscore2_01)), fun="mean", geom="line", color="black", alpha=0.5) +
  stat_summary(aes(x=as.numeric(year), y=as.numeric(voterscore_01)), fun="mean", geom="line", color="black", alpha=0.2) +
  labs(title="", x ="", y = "Average populist vote, %\n") +
#  scale_x_continuous(breaks = seq(1980, 2010, by = 2)) + coord_cartesian(ylim = c(0, 25)) +
  theme_bw(base_size = 14) +
  theme(axis.line = element_line(colour = "black"),
        axis.text.x = element_text(angle = 30),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.border = element_blank(),
        panel.background = element_blank()) +
  scale_y_continuous(sec.axis = sec_axis(~.*1, name = "Average anti-immigration attitudes\n"))

## Figure 1: Time series of populism and reforms by country 

plot <- ggplot(data = data, aes(x = year, y = FRPseatshare_int)) +
  stat_summary(fun="mean", geom="line", color = "black", alpha=1, linetype = 2) +
  stat_summary(aes(x=as.numeric(year), y=as.numeric(FRPvoteshare_int)), fun="mean", geom="line", color="black", alpha=0.5, linetype = 2) +
  stat_summary(aes(x=as.numeric(year), y=as.numeric(populismscoreTRW)), fun="mean", geom="line", color="black", alpha=0.2, linetype = 2) +
  stat_summary(aes(x=as.numeric(year), y=as.numeric(voterscore3_01)), fun="mean", geom="line", color="black", alpha=1) +
  stat_summary(aes(x=as.numeric(year), y=as.numeric(voterscore2_01)), fun="mean", geom="line", color="black", alpha=0.5) +
  stat_summary(aes(x=as.numeric(year), y=as.numeric(voterscore_01)), fun="mean", geom="line", color="black", alpha=0.2) +
  labs(title="", x ="", y = "") +
  #  scale_x_continuous(breaks = seq(1980, 2010, by = 2)) + coord_cartesian(ylim = c(0, 25)) +
  theme_bw(base_size = 14) +
  theme(axis.line = element_line(colour = "black"),
        axis.text.x = element_text(angle = 30),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.border = element_blank(),
        panel.background = element_blank())

fig <- dlply(data, .(country), function(x) plot %+% x + facet_wrap(~country))

marrangeGrob(grobs = fig, nrow=6, ncol=4, top=NULL)

FIG <- marrangeGrob(grobs = fig5, nrow=6, ncol=4)
ggsave(filename="Dennison_POQ-22-0153.R1 Figure 1.pdf", plot=FIG, height=14, width=9, units="in", dpi=600)

## Plot cross-sectional country-year data (Figure S1)

plot1 <- ggplot(data, aes(x = FRPseatshare_int, y = voterscore3_01, color = country)) + geom_point() +
  scale_color_grey() + 
  theme_bw(base_size = 14) + theme(legend.position = "none") + labs(title="", x ="", y = "Anti-immigration Attitudes (Combined)") +
  geom_smooth(method='lm', color = "black")

plot2 <- ggplot(data, aes(x = FRPvoteshare_int, y = voterscore3_01, color = country)) + geom_point() +
  scale_color_grey() + 
  theme_bw(base_size = 14) + theme(legend.position = "none") + labs(title="", x ="", y = "") +
  geom_smooth(method='lm', color = "black")

plot3 <- ggplot(data, aes(x = populismscoreTRW, y = voterscore3_01, color = country)) + geom_point() +
  scale_color_grey() + 
  theme_bw(base_size = 14) + theme(legend.position = "none") + labs(title="", x ="", y = "") +
  geom_smooth(method='lm', color = "black")

plot4 <- ggplot(data, aes(x = FRPseatshare_int, y = voterscore_01, color = country)) + geom_point() +
  scale_color_grey() + 
  theme_bw(base_size = 14) + theme(legend.position = "none") + labs(title="", x ="", y = "Anti-immigration Attitudes (Caughey et al.)") +
  geom_smooth(method='lm', color = "black")

plot5 <- ggplot(data, aes(x = FRPvoteshare_int, y = voterscore_01, color = country)) + geom_point() +
  scale_color_grey() + 
  theme_bw(base_size = 14) + theme(legend.position = "none") + labs(title="", x ="", y = "") +
  geom_smooth(method='lm', color = "black")

plot6 <- ggplot(data, aes(x = populismscoreTRW, y = voterscore_01, color = country)) + geom_point() +
  scale_color_grey() + 
  theme_bw(base_size = 14) + theme(legend.position = "none") + labs(title="", x ="", y = "") +
  geom_smooth(method='lm', color = "black")

plot7 <- ggplot(data, aes(x = FRPseatshare_int, y = voterscore2_01, color = country)) + geom_point() +
  scale_color_grey() + ylim(0, 1) +
  theme_bw(base_size = 14) + theme(legend.position = "none") + labs(title="", x ="\nPRRP Seat Share (Popu-List)\n", y = "Anti-immigration attitudes (Claassen & McLaren)") +
  geom_smooth(method='lm', color = "black")

plot8 <- ggplot(data, aes(x = FRPvoteshare_int, y = voterscore2_01, color = country)) + geom_point() +
  scale_color_grey() + ylim(0, 1) +
  theme_bw(base_size = 14) + theme(legend.position = "none") + labs(title="", x ="\nPRRP Vote Share (Popu-List)\n", y = "") +
  geom_smooth(method='lm', color = "black")

plot9 <- ggplot(data, aes(x = populismscoreTRW, y = voterscore2_01, color = country)) + geom_point() +
  scale_color_grey() + ylim(0, 1) + 
  theme_bw(base_size = 14) + theme(legend.position = "none") + labs(title="", x ="\nPRRP Vote Share (Timbro)\n", y = "") +
  geom_smooth(method='lm', color = "black")

ggarrange(plot1, plot2, plot3,
          plot4, plot5, plot6,
          plot7, plot8, plot9,
          labels = c("", "", ""),
          ncol = 3, nrow = 3)


